What is @aws-crypto/raw-rsa-keyring-node?
@aws-crypto/raw-rsa-keyring-node is a package provided by AWS that allows you to use raw RSA keyrings for encryption and decryption operations. It is part of the AWS Encryption SDK for JavaScript, which provides tools for encrypting and decrypting data using various key management techniques.
What are @aws-crypto/raw-rsa-keyring-node's main functionalities?
Encrypting Data
This code demonstrates how to use the @aws-crypto/raw-rsa-keyring-node package to encrypt data using a raw RSA keyring. It generates an RSA key pair, creates a keyring, and then encrypts a plaintext message.
const { RawRsaKeyringNode, encrypt } = require('@aws-crypto/raw-rsa-keyring-node');
const { KeyPair } = require('crypto');
const keyPair = KeyPair.generateSync('rsa', {
modulusLength: 2048,
});
const keyring = new RawRsaKeyringNode({
keyName: 'my-key',
keyNamespace: 'my-namespace',
publicKey: keyPair.publicKey,
privateKey: keyPair.privateKey,
});
const plaintext = Buffer.from('Hello, world!');
(async () => {
const { result } = await encrypt(keyring, plaintext);
console.log(result);
})();
Decrypting Data
This code demonstrates how to use the @aws-crypto/raw-rsa-keyring-node package to decrypt data using a raw RSA keyring. It generates an RSA key pair, creates a keyring, and then decrypts a ciphertext message.
const { RawRsaKeyringNode, decrypt } = require('@aws-crypto/raw-rsa-keyring-node');
const { KeyPair } = require('crypto');
const keyPair = KeyPair.generateSync('rsa', {
modulusLength: 2048,
});
const keyring = new RawRsaKeyringNode({
keyName: 'my-key',
keyNamespace: 'my-namespace',
publicKey: keyPair.publicKey,
privateKey: keyPair.privateKey,
});
const ciphertext = Buffer.from('...'); // Replace with actual ciphertext
(async () => {
const { plaintext } = await decrypt(keyring, ciphertext);
console.log(plaintext.toString());
})();
Other packages similar to @aws-crypto/raw-rsa-keyring-node
node-forge
node-forge is a JavaScript library that provides a wide range of cryptographic tools, including support for RSA key generation, encryption, and decryption. It is a versatile library that can be used for various cryptographic operations, but it does not provide the same level of integration with AWS services as @aws-crypto/raw-rsa-keyring-node.
crypto
The built-in 'crypto' module in Node.js provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions. While it is a powerful tool for cryptographic operations, it does not offer the key management and integration features provided by @aws-crypto/raw-rsa-keyring-node.
jose
jose is a JavaScript library for JSON Web Tokens (JWT), JSON Web Encryption (JWE), and JSON Web Signatures (JWS). It supports RSA encryption and decryption, but it is primarily focused on web token-based authentication and authorization, rather than general-purpose encryption and decryption like @aws-crypto/raw-rsa-keyring-node.
aws-encryption-sdk-javascript
The AWS Encryption SDK for JavaScript is a client-side encryption library
designed to make it easy for everyone to encrypt
and decrypt data using industry standards and best practices.
It uses a data format compatible with the AWS Encryption SDKs in other languages.
For more information on the AWS Encryption SDKs in all languages,
see the Developer Guide.
This package should only be used as part of the AWS Encryption SDK for Javascript.
For more information about the packages in this project
and how they can be used together,
see the main node package readme
Installing
npm install @aws-crypto/raw-rsa-keyring-node
Testing
npm test
License
This SDK is distributed under the
Apache License, Version 2.0,
see LICENSE.txt and NOTICE.txt for more information.